MDX Tutorial

What's my purpose  when write this tutorial ? It's just simple , support you with  the minimum skill  when deal with MDX and dialog , I don't know  what i could do for you but hope it good !

I. Requirement Knowledge :

          To know  what I show below , You  need some skills and of course  a "logic" brain to know  what you should do and have to do.  Some basics require:

 -  Alias , remote and  Identifiers : you need to see it  in mIRC Help File

 -  Dialog  and  control  

 

I list  and describe some  here(It's the most use when deal with dialog) :

- alias : /didtok /did

- Remote :   you must familiar with  mIRC remote , the way  It's trigger and  do its job , the most use  is

     on *:dialog:<event>:<id>: { command }  (A)

+ when user click a button (a list, treeview) ,   mIRC  (or MDX)  will trigger  (A) , It will choose  an suitable event  Like SCLICK (for single click) , DCLICK (double click) , INIT (init dialog) , Close  (close dialog) , EDIT (edit something) and MOUSE ,  There are something mIRC  can  perform for you when use with control. with MDX  you can Receive more complicated  event  . I describe some  here :

Right click  : RCLICK   ,  ITEM : change an item (in list) ,  Drop  , Drag . I will show you more detail when use with each style of controls

+  when trigger  (A) :  to identify  each controls   mIRC  need to  assign for  them  a  number (call <ID>) and  there are some ways to deal with <ID> in (A) , you  could use *  to describe all of them , or list them  like  <id1>,<id2>,<id3>  ( you can use * or 'List <Id>' with all most command or Remote -  except  * just use in   Remote  , and some commands does not have  "List  Style"  ( may be because It's hard to handle)

+ with mIRC  dialog  ,  when  trigger  (A) , mIRC use some identifiers  to store  <ID> number ,  event trigger, also  status of <ID> and some result when the event trigger . They are: (for example)

$devent : store  event  ;  $did : store ID ; $did().[content] (like $did(id).sel , $did(id).seltext ... )  to store status  or result

 

with mIRC, $did().<content>  just  return some information  (because the result in mIRC is simple )

but with MDX  you have a lot  of   results, depends on control's Events , I will  describe more details for each controls  later ,  but you should  hand  clearly   $did().<content>  of  each controls and  the result its return when use with mIRC Dialog . so you will be more better when  make  your script  with MDX

II. Use MDX

 

1)  To  use  MDX  with mIRC dialog ,  first of all ,  you must convert  a control (has ID number) to  MDX Control , this is just simple , but  you need to  do  some work  first :

- because MDX  couldn't  know  what dialog (ID) you want to convert , so you must  Mark  it first  use a Mark command :

<Call MDX> SetMircVersion $version

<Call MDX> Mark $dname [ $dialog(<dialog name>).hwnd  ]

<Call MDX>:  you have a lot  of ways to  call  MDX   , use an Alias  like 

alias mdx {
    if ($isid) { return $dll(mdx.dll,$1,$2-) }
    else dll mdx.dll $1-
}

or perform directly :  dll  mdx.dll 

or  add a Path like :  dll $pathmdx   with  $pathmdx  return full path and name for mdx.dll

I don't know  , this information is help or not , but  I hope you clearly know  what's actually happen with each commands so you could do it yourself

$version  and $dialog(<dialog name>).hwnd  return  version and handle  for  dialog ( I recommend you to download full of MDX and read  MDX help File carefully, what  each functions of MDX do for you . I don't include it  in my tutorial  and you should  download it  from Dragon Zap site , and  I think  It  will help you a lot .  In this tutorial   I just specify some methods to help you easy understand   what  really happen with MDX Control)

 

2) When you  finish  Mark  your dialog , we  move to  the next step  ,  convert   mIRC  Control  to MDX Control  by using  SetControlMDX  function

       <Call MDX> SetControlMDX  [dialog name] <ID[,ID,ID,...]> <control> [styles] > [plug-in filename] 

 

MDX Help has  describe it better than me  and  you should  have it , below here is  the way to use  some MDX Control

 

Listview  :

to make  listview : style report

The simplest style  for   ListView is :

   mdx SetControlMDX $dname <ID> ListView report > views.mdx

This command  will  convert  mIRC List  to  List view  style report. You  can find more detail for addition style in MDX Help and modify it follow  the form of  SetControlMDX  function. to suit with your need . Some scripters  don't know  actually each style  do  and  add a lot styles but not use them , and It's just  waste time and  quite dangerous if users  use these styles but They're actually not supported - so their scripts are wrong in some case (quite hard to happen but  A good scripter  need consider to All cases may  happen)

 

After change it to MDX CONTROL

   . you have to use  /did -i  <dialog> <ID>  1  headerdims <width>:<pos> <width>:<pos> ... ,  to control the size of each  fields of header  (Auto resize  or  specify  a  constant  value)

   . and then /did -i   <dialog> <ID>  1  headertext [+flags] [icon#] [text]{tab}[+flags] [icon#] ... to  set your header

number 1 is line 1 ,   MDX  use  it  to transfer data  between   mIRC  and itself . and  Our Data  actually begin from line  2 , when use with MDX  - ( mIRC  is begin from 1 .so  sometimes  You  cause some mistake  between this  "fool" - I hate it but It 's a must do)

   with Listview: style report  you  could  add  an  Icon  at  first of text  [icon#] [text],  but you have to init  an Icon List first  , This is  quite  confused  if you  have ever used MDX  -   in MDX  help file, It  has a section to describe  what  you have to do  to init  an Icon List - make sure you read it carefully   (I don't intend to  say it here)

 

to make  listview : style Icon:

 

dll $dl SetControlMDX $dname <ID>  listview icon > views.mdx

It's quite same  as   report style  but you  don't  need to  set   headerdims  and headertext  , Just  init Icon List  and then append it into list

 

A small Notice:  Frequently Asked Questions of MDX Help  is  a  "must read" section  so ensure you read it first  to rid out  some problems may be have  when you deal with  MDX

 

Treeview

- quite similar listview  and  I don't have to say much , but  It has many problems  need  to  discuss at later

This is a Line to convert  List  mIRC  to  Treeview: (just is an example)

 mdx SetControlMDX 1 treeview haslines hasbuttons linesatroot showsel > $vmdx

 

Other Control  are same :

 

4) Now  we  come  to the most complex  part ,  what  /did command  like  /did -i  do  and why  we must use it

- for the reason : MDX couldn't   receive  Init  information directly  so we  have  to used  /did  -i  to  transfer  information to MDX CONTROL (or to set init parameters for it) , /did -i  have many   form  depends on control style and  what  kind of data you want transfer  to MDX  Control . Should I say  more here ?  I  don't think about it   and  Now, we  go to a more exciting  section , That 's  example  Section .

III Example and individual control:

 

I have included  a mIRC script file  , you should look for it in "tutorial folder" and  load it into mIRC  to see the results (/load -rs example.mrc) - you should copy  mIRC.exe  into  "tutorial folder"  and load  example.mrc  to avoid  script couldn't found icon and pictures using with it  (also copy MDX into it - so the script  could run)

 

first of all ,  prepair  some  alias  to  return path of DLLs and  Image folder to use for these examples:

alias -l dmdx return $scriptdirdialog.mdx   
alias -l vmdx return $scriptdirviews.mdx
alias -l bmdx return $scriptdirbars.mdx
alias -l gmdx return $scriptdirctl_gen.mdx
alias -l udll return $+(",$scriptdir,mdx.dll,")
alias -l imgdir return $scriptdirImg\

alias -l mdx {

; determine : alias  is called  as  <command> or identifier to choose return value or not

  if  ($isid)  dll $udll $1-

  elseif ( $2- == $null ) return $dll($udll,$1,.)
  return $dll($udll,$1,$2-)
}

 


ComboBoxEx Control:

 

I take a simple example  first ,  A ComboBoxEx Control  :to  return  a color value , It's simple enough to do it with a small effort , of course you could use  A DLL name ColorCombo.dll  (by Hdel)  but with this example we could learn something

 

dialog colors {
  title "First example - Return colours"
  size 291 189 222 180
  box "", 1, 5 3 210 140
  combo 20, 95 22 104 285, edit
  combo 21, 95 52 104 285, edit
  combo 22, 95 82 104 285, edit
  combo 23, 95 112 104 285, edit
  text "Background:", 5, 8 27 83 13, right
  text "Information:", 6, 8 57 83 13, right
  text "Lines:", 10, 8 87 83 13, right
  text "Text:", 11, 8 117 83 13, right
  button "OK", 200, 81 150 56 20, ok
}
on *:dialog:colors:init:0:{

; These command  have been explained  in the previous section
 mdx SetMircVersion $version
 mdx MarkDialog $dname
 mdx SetControlMDX $dname 20,21,22,23 ComboBoxEx drop > $vmdx

 

; This command  use  to  init  an icon list  /did -i $dname <ID> 1  iconsize  <normal | small>

; It means: ComboBoxEX control  should use  small  or  normal Icon (16x16 or 32x32) to  load into list

; ComboBoxEX  use line  1 to  transfer  data  to  control  so  we start our data at line 2

             did -i $dname 20,21,22,23 1 iconsize small

 

; now  we assign some  icon into list

; use command:  /did -i $dname <ID> 1 seticon [list index] <[icon index,]filename>

; and while loop to reduce repeat code , because  we add 16 color icons  into list

; we just need  to init an Icon List one time and use it for during the time we use dialog

;20,21,22,23 :  "list ID"  to perform /did -i  on them , I have to say: you must careful if Command support List <ID> or not, MDX often support it  but a few commands  doesn't

 

 var %tmp = 0 | while %tmp < 16 {

did -i $dname 20,21,22,23 1 SetIcon 0 %tmp $+ , $+ $+($imgdir,colors.icl) | inc %tmp }

          

;After  Init  Icon List  , We need add some data on comboboxEX

; This alias will help  to add   Data  to control (we need add 16 colors  so we have 16 commands and a command to add No Color)

; use  /did -a to add

did -a <dialog name> <ID> 1  [icon#] [selected icon#] [overlay icon#] [indent#] <text>

;All paramaters are optional  , so we have many ways to  add data to  ComboBoxEx Control

; $1 = name dialog , $2 = <ID>

 

alias cor.cb {
did -a $1 $2 1 1 White
did -a $1 $2 2 2 2 0 Black
did -a $1 $2 3 3 2 0 Darkblue
did -a $1 $2 4 4 0 Darkgreen
did -a $1 $2 5 5 2 0 Red
did -a $1 $2 6 6 2 0 Brown
did -a $1 $2 7 7 2 0 Purple
did -a $1 $2 8 8 2 0 Orange
did -a $1 $2 9 9 2 0 Yellow
did -a $1 $2 10 10 2 0 Lightgreen
did -a $1 $2 11 11 2 0 Seagreen
did -a $1 $2 12 12 2 0 Skyblue
did -a $1 $2 13 13 2 0 Blue
did -a $1 $2 14 14 2 0 Pink
did -a $1 $2 15 15 2 0 Darkgray
did -a $1 $2 16 16 2 0 Gray
did -a $1 $2 17 1 No color
}

 

; continue our example ,  we want to  fill Data  in 4 IDs (20,21,22,23) so  we need this command
var %tmp = 20 | While (%tmp < 24) { cor.cb colors %tmp | inc %tmp }

 

;I assume we have stored colors for each IDs  in 4 variables  %clbg, %clinfo,%clline,%cltext  (use them for simple) and we need to show these colors in ComboBoxEx at the startup .

; use $dname or colors (dialog name) It  has same  results , but when use  $dname , we avoid to change code if we want to change dialog's name (or if you want to use the events for many "wildcard" Dialog Tables)

; why we add 2  here , because  our data  actually  start  at line 2  and  our colors have order 0-15  suit with  a position in ComboBoxEx data list , if  your data  doesn't have order , You should use another way to Ident  a "Data Line" in control. Identification order is necessary in most  case -  especially when we need to know exactly the position of line  to delete , Insert and overwrite  a "Data Line" .  It's quite  a hard part for many scripter . I will say it in List Box  because this example 's just a beginning  

 

did -c $dname 20 $calc(%clbg + 2)
did -c $dname 21 $calc(%clinfo + 2 )
did -c colors 22 $calc(%clline + 2)
did -c colors 23 $calc(%cltext + 2)
}

 

After Init and convert  <ID>  to  MDX Control  we  deal with some events : ComboBoxEx have 3 events (Edit, Sclick and Dclick) but  It  depends on your ComboBoxEx style (simple ,drop or dropedit)  . It is very important to dertermine what events A Control should have , in this example , we just take a color and  we don't use style dropedit . so we just have an event : Sclick (If you use dropedit style  you must  process  'Edit  event' )

These code store colors  for own purpose ( we just need to store colors when User click 'OK Button'  so  we process only for the event 'OK has been clicked'  - and OK button has  id number 200 - )


on *:dialog:colors:sclick:200:{

 Set %clbg $calc($did(20).sel - 2)

 Set %clinfo $calc($did(21).sel - 2)

 Set %clline $calc($did(22).sel - 2)

 Set %cltext $calc($did(23).sel - 2)

}

 

we have finished our first example , In this example  we  can  see some points :

- The way to  init  and  convert  mIRC control  to MDX  control

- Get used to  with  the  way  MDX transfer data use /did -i , /did -a

- basic information about   "Identification order"  and  Events  ( a higher skill need when deal with List or  Tree view)

 

List View

 

Now  we discuss something about  List  view , It's  quite  same as ComboBoxEx , however  I will take  a complicated example to  show you some advance skills  when deal with MDX , also  Addition information about  "Order" (insert ,overwrite, delete a line)

 

the first  example is  a control panel (List view style Icon) . all most scripts  now  use  a control panel  to interact  with other people , This dialog  is  very simple , because I only use  Listview to make it simple 

 

dialog cpanel {
   title "Control Panel - [/cpanel]"
   size -1 -1 200 120
   option dbu
   list 2, 4 1 192 112, size extsel
}

on *:dialog:cpanel:init:0:{
  var %m = $udll
  dll %m SetMircVersion $version
  dll %m MarkDialog $dname
  dll %m SetControlMDX 2 ListView infotip autoarrange > $vmdx
  did -i $dname 2 1 IconSize normal large
  cpanel.initicon
}

we can see It's same  as   ControlBoxEx , so I don't think your have problem here.

cpanel.initicon is an alias to init icon  from  a file . We need  an alias to return file path here

alias cpanel_f return $+(",$scriptdircpanel.txt,")

 

and also  we need  a format for  this file. what  data  you need to store ?   Icon Path for an Icon in list , command  assign with each Icons , and the Title  for each icons , so we could store it like  (use | to separate each fields)

              Title|Icon Path|command  (Icon Path = [Index,]<Filename>)

This is  a  format  for a  Line  in  file

 

alias  cpanel.initicon {
  var %file = $cpanel_f,%line = 0
 did -r cpanel 2
 did -i cpanel 2 1 clearicons normal
 while (%line < $lines(%file)) {
        inc %line

       ;store  Title in $1 , Icon Path = $2 ,command = $3 ....
       tokenize 124 $read(%file,%line)

 

        ;check for an  icon file exists  or not , If it doesn't exists  use default Icon

        ; (Icon Path = [Index,]<Filename>)  so we need to use  $gettok  to get file name

       var %iconfile = $iif($gettok($2,2,44),$ifmatch,$gettok($1,2,44))

         if (!$isfile(%iconfile)) var %iconfile = $imgdir $+ cpanel.ico
        else %iconfile = $2

 

     ; Add Icon into Image  List  and  also Add a 'line' into Listview

       did -i cpanel 2 1 SetIcon normal 0 %iconfile
       did -a cpanel 2 0 %line  $1
   }
}

we could see  some skills here:

- The ability  to store and Load Icon into  MDX ,Use  /did -i  and /did -a  as a same time.

- use tokenize command to get a field value
- Use   did -i cpanel 2 1 clearicons normal to clear  icon list first , because we want to use it later so we should use this command.

 

With this example ,Events will be received are : User  can  click on Icon to trigger SCLICK ,or double click to trigger DClick;  - the way I process it : SClick to  inform command  and DClick to call command . You should determine what function  an Event call and return results for user at the first  and then write the code follow it, so never lose yours way

 

now  we have to  Identify  what "Data Line"  user have  click (or dclick) in it . if we use  $did(<id>).sel  It's may be  inaccurate if the items in list  are sorted with an order diffrent with orginal  Data. so  we use $did(<id>).seltext.

with Listview It  returns  some information as this format :

[indent#] [+flags] [icon#] [overlay#] [state#] [text]{tab}[+flags] [icon#] [overlay#] [state#] [text]{tab}...

 

{tab} to separate  each fields of List .  with control panel   we just  use one field . so the  $did().seltext  only return :

[indent#] [+flags] [icon#] [overlay#] [state#] [text]

 

on *:dialog:cpanel:sclick:*:{ echo -s = $did(2).seltext }

 

If you  use this remote  you could see  the result when click Icon 1 is  0 +fs 1 0 0 Icon 1

  indent = 0

  flag = +fs

 (f The item has the focus. (In other words, the dotted box border)
  s The item is selected.)

  icon = 1  (posittion  of  Icon in list icon )

  ovelay  and state  we 'r not used  , so They have value 0

  Icon 1  is  the title

Total is 6  fields  separate with   Blank character ($chr(32) -  spacebar) ,  so we use  $gettok  to  get  Icon text . It's #6

$gettok($did(2).seltext,6-,32) . This is only  right  when we are  at the first column  and  just have one column only . If you have more than one column  . you must  use  $gettok($did().seltext,<#column>,9)  , To  receive data of a column and store it in variable  or  you  could  also  use /tokenize  command  to store all columns  in $1-  (In case you  don't  need to use orginal $1- )

If the column  is 1st  use  $gettok(<data for the column>,6-,32)  otherwise use  $gettok(<data for the column>,5-,32)   to  get  data text of the column .

I  say too much  here  but  It's necessary for future  when you want to  deal with it yourself

 

now  continue  the example :   we need to know  what user click   so we  use  $did().seltext  and  get  data text  of the column . when we have data text .  we could retrieve  data  for one line  in  file , which use to init our icon list at the first. To retrive we must compare  data text (Title Icon)  with the Icon  in file  to have  the line or use  $read(file,w,*data text*) to match . it is inaccuracy for some case so we write our  alias to compare it .

 

; This alias  return  a line follow  the  Title of  icon by compare it with  each  lines

; input :  Icon Title  ;  Output :  full data line

alias Get_A_Line {

  var %file = $cpanel_f,%line = 0
  while (%line < $lines(%file)) {
        inc %line

       var %linetext =  $read(%file,%line)

       if ($1- = $gettok(%linetext,1,124))  return %linetext

 }

}

 

And now  we can  start  with remote :

 

on *:dialog:cpanel:sclick:*:{
 var %line = $get_a_line($gettok($did(2).seltext,6-,32))
 echo -s Command for Click Icon : $gettok(%line,3,124)
}

 

then we check the  result  of this remote , It's  echo out  of  status screen Quite a lot sentences :

Command for Click Icon :
Command for Click Icon : echo -s call command assign with Icon3
Command for Click Icon : echo -s call command assign with Icon3

 

do you see amazing ?  because  A lot scripters  doesn't known about  Page and  Event  of  MDX . Just  use sclick Like mIRC, but actually  MDX  return a lot  of value  through   this remote,  to  know what is return exactly  I take a little time to explain  Page  (This is take form MDX help) :

 

Some controls have a large amount of information that they can provide to your script; much more than can be provided on a single line. To remedy this, controls using the output page system divide up the information they have available into output pages. Each page has a name, which can be found in the individual control documentation, as well as data associated with that page. The format of a page's data will also be listed in the individual control documentation.

To read data from a page, your script must tell the control which page it wants to read before it can actually read it. More than likely, the control will have a command named page for just this purpose, often executed using a /did -i on line 1 of the control:


/did -i myDialog 123 1 page pageName

Following this command, your script should immediately use $did() to read information from the control, typically from line 1, as some control events may switch the active output page to the most pertinent one for that event. You should be able to use mIRC's token functions to separate the page information from any extra information the control may provide, such as the name of the last event or the active page name.

It is probably easiest to make an alias that performs the output page reading without needing to remember that it requires two steps. Such an alias might look something like this:


alias mdx.page {

 var %dname, %did

 if ($0 = 1) { set %dname $dname | set %did $1 }

 else { set %dname $1 | set %did $2 }

 did -i %dname %did 1 page $prop

 return $gettok($did(%dname, %did, 1), 3-, 32)

}
Then a script could just use $mdx.page($dname, $did).pageName or $mdx.page($did).pageName to retrieve an output page's data.

Since most of the controls using output pages only return the last event name and page name as extra data, using "3-" in the $gettok() command will strip out the data that is not directly part of the page itself.

 

Now  we know  what's  a page ,  so we will check  it  a litte with  our example  , to know  what page has  returned  when we click  at  Icon 1 , write  a remote  like this :

 

on *:dialog:cpanel:sclick:*:{ echo -s  Page is : $did(2,1) }

after click, we have result :

 Page is : item recent 2
 Page is : item recent 2
 Page is : sclick recent 2

It's now clearly ,  MDX  has  return  ITEM  and SCLICK Page  for   on *:dialog:cpanel:sclick:*:{} , so we could  rewrite our remote  to have a more  accuracy :

 

on *:dialog:cpanel:sclick:*:{

 if  ($gettok($did(2,1),1,32) = sclick) {
   var %line = $get_a_line($gettok($did(2).seltext,6-,32))
   echo -s Command for Click Icon : $gettok(%line,3,124)

 }
}

It's not bad ,  continue  with double click event, with this event  . we don't  need to use page  because It's quite same as  mIRC:

 

on *:dialog:cpanel:dclick:*:{

   var %line = $get_a_line($gettok($did(2).seltext,6-,32))
   $gettok(%line,3,124)

}

 

Should  we  continue  with this example ?  That's your job , you could  developed it follow your  desire.  I will take another example  to  explain  more clearly  about  Listview .

What  we  take   with  this example :

- Known  what a page  is

- A way to  Load  a file   use /tokenize 

- deal with a simple control panel  ( Now you can easily make for your own )

 

List View Style Report

 

This style is the most  using  ,  But I don't see any tutorial  explain  detail about  it ,just  the surface .so  we need an example that can be exhibit  something useful . I  take  an example  :  we  will  create  a list of  our friends,  with their symbol  at first nick  and some notes  about them - however  I just  take a little icon to do ,more icon or picture  , It's your job.

Now Move on:

 

Dialog FriendNotes {
title "FriendNotes example"
size -1 -1 214 107
option dbu
list 1,3 3 206 88,extsel size
button "OK", 2, 89 94 36 10, ok
}

convert it  to  MDX and  List View Style report :

plus some style here :  editlabels showsel sortascending droptarget Rowselect

+ editlabels Allows the user to edit item labels by clicking on their text

+ showsel Always show the selection, if any, even if the control does not have the focus
+ sortascending Sorts items based on item text in ascending order (to sort Nicks)
+ droptarget The ListView can act as a target on which files and items from other MDX controls can be dropped

+ rowselect When an item is selected, the item and the entire row it is in is highlighted. This style is available only in conjunction with the report style.
 

Showsel ,rowselect and sortascending are used frequently  , editlables  and dropptarget  are seldom , however This is an example  so I take it, with them we can  understand  more clearly about Page  and  what's  useful with these style

Single is not used , because  we will allow user select multi-lines at  a same time , and  of course we must write some code to deal with it.

I usually take some code, which has written, to save my time , I don't know   that is rip or something , just because I'm lazy to do them , It's  bored and don't  have any  point  to re-make it, Let's our time to some new and useful things. but it seems many scripters don't want  others use their code ! feel  a bit disappointed here. ah, stray a little,sorry, now we continue our example

 

This is  the most use alias  to insert tab between words in sentence :

alias tab {
  if (!$0) return $chr(9)
  var %tablist = $1, %i = 2 

  while ( $ [ $+ [ %i ] ] ) { inc %i | set %tablist $+(%tablist,$chr(9),$ifmatch) }
  return %tablist
}

$tab(header1,header2) = header1 $+ $chr(9) $+  header2 ....

you could  use   this alias or  write directly. I usually use both of them 

 

::> like control panel  we need a file to store information , But this time  format of a line  is :

 <Friend Nicks/Name>|Icon or value 0 (not used)  or 1 (use default)| <notes>

 

   alias friendnotes_f return $+(",$scriptdirfriendnotes.txt,")

 

And  an  alias to init  'Data lines, This is  a bit  complex more than control panel, because  we must control icon for each lines (Nicks). so we must  to handle  the index  of currently icon ,and apply it imediately for inserting data

 

alias  friendnotes.init {
  var %file = $friendnotes_f

  var %line = 0   , %indexicon, %CurrentIcon = 1

  var %nline = $lines(%file)

; Clear List and Icons of List first , because we must apply each icons for each nicks
  did -r friendnotes 1

  did -i friendnotes 1 1 clearicons normal

 

; Add a  default  Icon  for all nicks  at index 1

 set %defaulticon $imgdir $+ user.ico

 did -i friendnotes 1 1 SetIcon normal 0 %defaulticon

 

  while (%line < %nline) {
        inc %line

       tokenize 124 $read(%file,%line)

      ;$1-  contains  <Friend Nicks/Name>    Icon or value 0 (not used)  or 1 (use default)    <notes>

 

    ; Now  we  store icon  for  currently line  in  %indexicon  (of course take it from file and process it a little)

      if (!$2) %indexicon = 0

      elseif ($2 = 1) %indexicon = 1

      else  {

         var %iconfile = $iif($gettok($2,2,44),$ifmatch,$gettok($1,2,44))

         if (!$isfile(%iconfile)) %indexicon = 1
        else {

          did -i friendnotes 1 1 SetIcon normal  0 %iconfile

          inc %CurrentIcon

         %indexicon = %currentIcon

        }

    }

 

; Now  Add  Line  into  list

; Use command : did -a <dialogname> <id>  [indent#] [+flags] [icon#] [overlay#] [state#] [text]{tab}[+flags] [icon#] ;;[overlay#] [state#] [text]{tab}... (check this command in MDX help  for more detail)

; we  don't use  any styles  so that  we represent it by  a plus (+)

 

 did -a friendnotes 1 1 + %indexicon %indexicon 0 $1 $+ $chr(9) $+ + 0 0 0 $3

 

; or use  a simple command like :    did -a friendnotes 1 + %indexicon %indexicon $1 $chr(9) $3

; This command  can be wrong in some case (when $1 is number) , because the way  MDX analyze  your parameters  so It depends on your choice 

   }
}

 

when All are  in position ,  we can  write our  remote , just simple  like  this:

 

on *:dialog:FriendNotes:init:0: {
 mdx SetMircVersion $version
 mdx MarkDialog $dname
 mdx SetControlMDX $dname 1 Listview report editlables showsel sortascending droptarget grid> $vmdx

 did -i $dname 1 1 headerdims 120 280
 did -i $dname 1 1 headertext $tab(Nicks,Notes)

 friendnotes.init
}

 

Now  we must  deal with  the events , User  can do  some events Here :

- Click a Line  in List : MDX return stateclick , rclick, sclick and Item  event (pages)

- Double click : Dclick

- Edit  to change  a Nick (by click on Nick name) : MDX will return beginlabeledit endlabeledit cancellabeledit for this action , but we just need to now result so  we   take  endlabeledit pages

- Drop a file into list : yes we accept  but  It's should a File which has been stored nicks , so  we need some marks to know that's the file suit with the format ,which use to store nicks. The mark  I use  That's the first line of file must  have  a sentence like :  "!This is a file Create by  Friendnotes"  or  simple "[friendnotes]" , so  the alias friendnotes must rewrite a little  to check the format of a file , and data  is begin at line 2 , also  we need this alias have ability to process a file name from its parameters

 

alias friendnotes.init {

var %file = $iif($0,$1-,$friendnotes_f)

if ($read(%file,1) != friendnotes)  { echo -s Invalid  File Type, %file is not a file use for friendNotes | return }

var %line = 1
....................

}

just need to change a line  and  add a line , It's simple

MDX will return dragdrop begindrag enddrag dropinfo  drophilite drop for  drop action ,  we will deal with it later

- User click on header : MDX return headerclick

 

You will find  these events quite  difficult  If you are not read  the first part of this turtorial  carefully .  let's  take  a breath  and think about  what  we have  after  a lot  of  lines, also  you need to check these events in MDX help to know clearly about them  (of course mIRC doesn't have these events but MDX return them through $did() ) :....................................

 

continue  with  our  example, we  go to  the  remote  to process  events  the simplest  form  to code is

 

on *:dialog:<dname>:sclick:<id>:{

 if  ($gettok($did(<id>,1),1,32) = sclick) { }
}

but we don't use  this  form, we use another form  like this : (stored the events that MDX return to use later)

 

on *:dialog:<dname>:sclick:<id>:{

   var %action = $gettok($did(<id>,1),1,32)

    if  (%action = sclick) { }

   elseif (%action = rclick) { }

..................................................
}

and we need  an alias   to retrieve an output page's data. (you should preview  what's a page that I have said)

 

alias mdx-info {
if ($0 = 1) { var %dname = $dname , %did = $1 }
else { var %dname = $1 , %did = $2 }
did -i %dname %did 1 page $prop
return $gettok($did(%dname, %did, 1), 3-, 32)
}

 

All preperation have been done , now  we just need to write some code for events . These code I have take  quite a lot from MDX help , They describe clearly  about MDX  and when you need just copy them into your script/addon , they'r very dynamic,however If you want a better speed when mIRC run this remote  you can  remove $did($dname,<id>...) by $did(<id>....), because It's just redundancy when  use in remote.

 

  $did($dname,$did).sel =  $did(1).sel  : the positon  of a line which user click

 $did($dname,$did,$did($dname,$did).sel)  =  $did($dname,$did,$did(1).sel).text  =  $did(1,$did(1).sel).text = $did(1,$did(1).sel). All is  the same , but  the lasts  only apply for our example,which replace <id> = 1($did = 1) and remove $dname

 

on *:DIALOG:friendnotes:dclick:1:{

  var %seltext = $did($dname,$did,$did($dname,$did).sel)
   echo -s Double-click on $did($dname,$did).sel ( $+ $iif($gettok(%seltext,5,32) == 1,un) $+ checked): $gettok($gettok($gettok(%seltext,2-,32),1,9),2-,32)
}

 

on *:dialog:friendnotes:sclick:1:{

   var %action = $gettok($did(1,1),1,32)

   if (( %action == sclick ) || ( %action == item ) || ( %action == stateclick ) || ( %action == rclick )) {

     ; store  total selected  Items in %maxsel
       var %maxsel = $did($dname,1,0).sel
       var %sellist
       var %cursel = 1

 

     ;  Add  #Lines Selected  in %sellist  variable , You can add some of your code  in this loop , use  $did($dname,1,%cursel).text  to get  a data line .

 

       while ( %cursel <= %maxsel ) {
            set %sellist $addtok(%sellist,$did($dname,1,%cursel).sel,44)
            inc %cursel
       }

      ; echo out  mIRC status  what sels  have been clicked  or selected , you  can replaced this code  by refresh List or  whatever, I hope you can understand  the code ,because  It's not  use for beginner

 

      echo -s Selection $+ [[ $+ $gettok($did($dname,$did,1),1,32) $+ ]] ( $+ %maxsel $+ ): %sellist

 

 $+ [[ <something> $+ ]] <--- This just  a way to Print "[<something>]" to mIRC screen because [ ] use for evalution in mIRC script (expression or variable)
   }

 else if ( %action == drop ) {
     var %dropinfo = $mdx-info($dname,$did).dragdrop
     echo -s di: %dropinfo
      var %method = $gettok(%dropinfo,2,32)
      var %type = $gettok(%dropinfo,3,32)
      var %filecount = $gettok(%dropinfo,4,32)
      var %flags = $gettok(%dropinfo,1,32)
      var %fromdlg = from dialog item [[ $+ $gettok(%dropinfo,5-6,32) $+ ]]
      var %button = unknown
      if ( r isincs %flags ) set %button right
     else if ( m isincs %flags ) set %button middle
     else if ( l isincs %flags ) set %button left
     echo 4 -s Dropped %filecount %type $+ (s) $iif(%type == mdx,%fromdlg) on listview item ( $+ $mdx-info($dname,$did).drophilite $+ ) with %method method, using %button mouse button:
     var %cfile = 1
     while ( %cfile <= %filecount ) {
           did -i $dname $did 1 getdrop %cfile
            echo 3 -s %type %cfile $+ : $mdx-info($dname,$did).dropinfo
            inc %cfile
       }

These code  are  a bit confused  , I explain  a little :

This is relative with drop events The user has dropped some data onto the ListView. Your script should take appropriate action. The dragdrop page contains information on the item being dropped, and the drophilite page tells which item the data was dropped on to. Your script can call the getdrop command to change which dropped item the dropinfo page should retrieve information on.

these code are quite  long  , but  It needs  when we don't know , after you  understand them , I have rewritten some to suit with our example,It's more simple, now move on :  we want  to  User  can drag  a formated File   to  Our List  and  Our List  process with it (multiple file can be proccessed but we just process once for the simplest). so  we just replace some codes here:

- we don't need multipe file,so we remove Loop :    while ( %cfile <= %filecount ) { }

- we Just need  $mdx-info($dname,$did).dropinfo to get a filename and  rewrite code like:

 

 else if ( %action == drop ) {  friendnotes.init  $mdx-info($dname,$did).dropinfo  | return }

you can see the result : first use command  /did -r friendnotes 1 (to clear the list)  and drag friendnotes.txt  into list , wow we finish it here ,  the  remain is your job ,  you can do  everything you want with  Drop Events

we just need to process with Editlabels and Headerclick , this is these code , It's quite easy  and I don't have much to say you  can take  $mdx-info($dname,$did).labeledit  when endlabeledit  to use for your own purpose , or  $mdx-info($dname,$did).headerevent  to know  what the header is clicked

 

else if ( %action == beginlabeledit ) echo -s Beginning label edit on ListView item $mdx-info($dname,$did).event
else if ( %action == endlabeledit ) echo -s Ending label edit on ListView item $mdx-info($dname,$did).event - you typed " $+ $mdx-info($dname,$did).labeledit $+ "
else if ( %action == cancellabeledit ) echo -s Cancelling label edit on ListView item $mdx-info($dname,$did).event
else if ( %action == headerclick ) echo -s Clicked ListView header $mdx-info($dname,$did).headerevent


}

..................................................
}

 

you have take a lot of information to get data of a line through pages ,  But  I  haven't said  about  how to deal with it , This is your works . with  the 'Data Line' you had taken , you can do  whatever  with  it . and  apply it to control again , Use  /did -a or  /did -o command (format is the same as the command when we  started  Add a 'Data line' into List . so the remain is quite simple but depends on your skills . It could be hard or easy and It relatives with your knowledge about  scripting and mIRC

 

I should  finish this example  here , In this example  , you could see  more clearly about pages  and the  way  to use it and also deal with some new events  MDX support

 

Toolbar

Now  we  relax a little  , to do a simple  work ,  make  a Toolbar <Id> now It's more easy  and we can do it quickly , first of all you need to make  a dialog, which have a List (have <Id>  1  or whatever number) ,  after that convert it  to  Toolbar use bars.mdx like this command

       mdx SetControlMDX $dname <id> toolbar nodivider flat wrap > $bmdx

Init  an Icon List,MDX have a command  to init  icon for  this style

       did  -i  <dialogname> <id> bmpsize <width> <height>
This command is simple ,use to set the width and height  for  all  Icons of  toolbal

then  you must use  SetImage  to add Icons.  To change some aspects  of the toolbar  use  setbkg (to set background colors plus picture file) , setscheme and Pad , you can find more information about these commands in  MDX help
after  Init Icons, You need to  add 'data lines'  into List , It's  just  a simple work (use did -a/did -o ...)  but take care  a little about  flags , some flags will be useful. (aWxv ... )
 

if you finish all works  above  ,  just  need to write a remote like this

on *:dialog:<dialogname>:sclick:<id>: {

if ($did = <id>) {

   if ($did(<id>).sel = 2) { < process for first button> }

   elseif ($did(<id>).sel = 3) { < process for second button> }

...............................................................

}

}

All  is simple (^_^) , and you need do it yourself , or learn something  from these codes , I take it  from MDX Tutorial
by tek ,  because  It's  too simple  and I'm Lazy (lol :) do you see of it )

Example dialog code
dialog example {
title "Example"
size -1 -1 1000 18
option dbu
list 1, 1 2 1000 14, size
}

on *:dialog:example:init:0:{
;You must ALWAYS do this if you are going to use mdx on a control or dialog
;This tells mdx your mIRC version and the dialog you will be adding controls to
dll mdx.dll SetMircVersion $version
dll mdx.dll MarkDialog $dname
;This sets the desired listbox control to a toolbar control, we will look at the different styles later
dll mdx.dll SetControlMDX $dname 1 ToolBar list arrows flat wrap nodivider > bars.mdx
;Takes away the dialog's titlebar and border and takes off the control's border
dll mdx.dll SetDialog $dname style
dll mdx.dll SetBorderStyle 1
;Sets icon size
did -i $dname 1 1 bmpsize 16 16
;Adds icon IDs to the control
did -i $dname 1 1 setimage icon small icon1.ico
did -i $dname 1 1 setimage icon small icon2.ico
;Adds items into the control
;The bolded +a is called a FLAG - we will go through them later
;The bolded 1 is the icon ID that we set previously, using 1 will return icon1.ico, using 2 would return icon2.ico

;The bolded Hello is item's text, this can have a value or be left blank
;The bolded Tooltip! is the items tooltip, this text will appear when you hover over the item
did -a $dname 1 +a 1 Hello $chr(9) Tooltip!
did -a $dname 1 +a 2 Goodbye $chr(9) Tooltip!
;use this if you want to dock the dialog over mIRC's default
dll ktools.dll DockToolbar $dialog($dname).hwnd

}

;this is the event that will determine which button you clicked and what it will do
on *:dialog:example:sclick:1:{
;Sets %click to the ID that you clicked, the first toolbar item will return 2
var %click $did($dname,1).sel
;Checks if %click is the same as the selected item
if (%click == 2) {
;Command you want to use goes here!
}
elseif (%click == 3) {
;Command you want to use goes here!
}
}

after read this example , I  discover  a bit depressed . this example use  Ktools.dll  when I didn't tell it for you before , but no problem here . I  explain something now :

  -  If you want  to make  a toolbar , which replace default toolbar ,  you  need to use MDX to set dialog style and a dockable DLLs  to dock your dialog ( I  recommend  Rebar.dll  , because It's the best now however It's your choice)  command need to use  is :

       <Init MDX>

       <Call MDX> SetDialog $dname style

       <Use DLL  to  dock your  dialog>

 

Process Bar

 

You need a process bar . It's just simple,  first  create a dialog with  List <Id> ,  then convert  <ID>  to ProcessBar

 mdx SetControlMDX <id> ProgressBar > $gmdx

after that,  you need  to  set  min and  max  value  for  process bar  , use this command:

  did -a <dialogname> <id> 0 <min> <max>

if you  want to change colors  use /did -a <dialogname> <id> BarColor <value>  or BGColor <value>  (with  WINXP this command may not take affect) (<value> is  rgb colors , Try  $rgb(00-FF,00-FF,00-FF) , FF = 256 :)  to return <value>)

Then, Just  need to fill value for Processbar , and watch it runs :)

  did -a <dialogname> <id> <value>  

The methods to fill value : 

- may be in a loop  with <value> increasing or decreasing (processbar will be up or down)

- use a timer  to count down or count up

Many methods for you to fill value , and  I don't have any  criterion for them , This is  a little paragraph  take from MDX Tutorial Contributed by pr0nking

 

Just a simple text field (enlarged) and MDX'd up, now the way to do this, thanks to my good friend Joe Honer (Triple-H) he gave me this alias, i'll show you all code:

dialog prog {
title "progress bar"
size -1 -1 129 44
option dbu
text "", 1, 31 32 57 8
text "", 2, 1 8 126 16
}

init:

on *:dialog:prog:init:0: {
mdx.load
dll $mdx SetControlMDX $dname 2 ProgressBar smooth > $ctl
load.up
}

Alias to make counter work:

alias load.up {
dialog -m prog prog
var %dsg = 0
while (%dsg <= 100) {
inc %dsg
.timer -m 1 $calc(25 * %dsg) .did -a prog 2 %dsg 0 100
}
}

try it if you wish :) its quite good, can be used for purposes such as: loading scripts, if you have made an addon, make it so that it loads, or if you require a download of some sort..Its quite fun and jus' makes thigns look decent :)

 

Let's Look at the code a little  , you could see  the Init  Control MDX  and an alias  Load.up  but  don't  see command

  did -a <dialogname> <id> 0 <min> <max>

where it has gone ? , Look  at   did -a prog 2 %dsg 0 100 ,   the author  fill it here , But It should avoid  because we just want  to set min and max  at the first time  (or  when init  a new  min max value)

and  these code  are  a bit useless, because It's not actually attach  with  a process , It's an "independent  dialog"  , so It's not describe accuracy  the time of process (long and short  is the same) .  I don't  think you should use this unless you're a bad scripter (:))  you should  apply   a small code  in your  loop (or at some mark time,which need to move pointer)  Like  this

inc %cmv_count

.did -a prog 2 %cmv_count

if  you want   to move  more than a point  , you should  use this command to move (Use at first to Init value only)

  did -a <dialogname> <id> Step [value] 

 

with the combine of  SetDialog command  and  set colors  of control , you can make your processbar ,Toolbar...  a more beatiful GUI , Please check  command SetDialog  and set colors of each controls in MDX Help File

 

The Last Part  of  this  tutorial  is  Treeview and some tips when deal with MDX (also mIRC)  to better  scripting or coding

 

TReeView

Recently  Many scripters  have used Treeview to make Setup Dialog(main configuration), You can see them in many scripts  .Or  you can see in some scripts  when They  try to replace  switchbar  to a new form.Or  MSN Messager ...

Do you  want  to make one? It's  hard  for someone  who have never made a Tree view. But  with my example , I hope It become easy like 'watch a TV ' :) . All you need to do  is  follow my instruction , and read carefully  the example :

 

- First, the basic step is  Convert  an ID  to  a Tree view , It seems quite familiar here

- Then ,You need init an Icon List  if you want  your Treeview  has some  Icons (of course If you want to  have a dynamic Icon List, You should  fill it  when you apply  'Data Line') , and Fill Data for  Treeview

we have some problems here Fill data ,It was seems too hard for me when  I used it the first time because  I don't know how to do, Let's  me tell you  the way , It's quite simple :

 

" The MDX TreeView has a concept of “working branches,” similar to navigating a directory hierarchy in an MS-DOS or UNIX shell. Before you can start modifying a branch and doing things like adding items, you must set that branch to the active branch by using the cb command. From there, you may use /did -a or /did -i (with the first line being line 2) to add items, or /did -d to remove an item and all its child items. You should not use /did -o with the TreeView control, because mIRC implements it as /did -d followed by /did -i, and as a result, it will end up deleting all the item's children. Instead, if you wish to replace the text of an item, you should use the replaceitem command. "

 

That's  we need , but how to use   cb command ,You must read  it form in MDX help, It will tell you about the form of a CB command , but when you use  this command. I could say , everywhere  when you need changed a value ('Data line') or Append  a value to Treeview or get a value:

The  most used are :

To Get Value:

 var %sel = $mdx-info($dname,$did).select   /*(1) */
var %branch = root $gettok(%sel,2-,32) up  /*(2) */
var %line = $gettok(%sel,-1,32)                    /*(3) */
did -i $dname $did 1 cb %branch                   /*(4) */
var %branchtext = $did($dname,$did,%line)   /*(5) */
echo -s TreeView item selected - %sel - Text is: %branchtext

 

first  we need to know  what  branch is  select  (Use  select Page - command (1)).  Then  take the position of Parent  use command (2).  change it  to active branch(the currently active branch  is your  recently Add or Append ...., so It have to change) , after that  you  can use $did($dname,$did,%line) to get a 'Data Line'.

To Append Value:

 

var %count = 1 , %number_of_data = ?

  while (%count <= %number_of_data) {

    did -i $dname $did 1 cb root  /*11*/

    did -a $dname $did  [+flags] [icon#] [selected#] [overlay#] [state#] [integral] <text P1>{tab}[tooltip text]

;Update child of parent(currently Add) if it has :

      var %number_of_child_data = ?

      var  %count_child = 1 ,%pos = $mdx-info($dname,$did).recent

     while (%count_child <= %number_of_child_data)  {

        did -i HTManager 1 1 cb root  %pos /*12*/

         did -a $dname $did  [+flags] [icon#] ......... <text child P2>{tab}[tooltip text]

         .............................................

         inc %count_child

    }

    inc %count

  }

This is a typical Loop for  add 'data Line' into a Treeview. You should read and understand it, and  apply it  for your script , or depends on your skills you could write another form. It's quite easy  and doesn't have much to say. except you can move /*11* and /*12*/   outside of Loop  if  you don't do any actions which  change  active branch in Loop.

 

To Modify Value:

var %branch = $mdx-info($dname,$did).event        /*(1) */
var %subbranch = $gettok(%branch, -1,32)             /*(2) */
var %edittext = $gettok($mdx-info($dname,$did).labeledit,1,9)   /*(3) */
echo Ending label edit on %branch -- text changed to %edittext      /*(4) */
did -i $dname $did 1 cb root %branch up                /*(5) */
var %oldtxt = $did($dname,$did,%subbranch)        /*(6) */
var %newtxt = $gettok(%oldtxt,1-4,32) %edittext  
did -i $dname $did 1 replaceitem %subbranch %newtxt

 

I take a modify example when User change Label of an Item by edit directly on Treeview Item: the event page indicates which item was edited, and the labeledit page indicates the text that the user entered

- use command (1) to  get  event page

- command (2)  to  get currently active branch (the branch  is edited)

- command (3)  to get the text  that user entered

- command (5) (6)  is similar  Get value to change the branch  to its parent (But this case is use directly) and get the text  of old Item

after that , Because  we had changed  the  active  branch  , so  we just  need to use  did -i ... ReplaceItem ... to change the 'Data Line'

you  can replace

 %newtext by  another text,which has form:

  [+flags] [icon#] [selected#] [overlay#] [state#] [integral] <text>{tab}[tooltip text]

It's  quite  a bit complex more than List view , but  the operation is the same

%subbranch by currently  active branch  use page Recent  or Select to get it  or you must store it in a varible. This variable must be describe exactly the position of branch  that you want  to change or modify it

Above, there are some basically codes to help you  have a  good beginning  when deal  with Treeview, of course when use the Treeview , you need more than that , but  I'm  still don't know  What have to say , may be  an upgrade of this tutorial I will  update  and Add more information

 

why we don't  try  to read  another tutorial , This is  a  Treeview Switchbar Tutorial Contributed by Synthet|c  , It should be a good example  to read and review  what we have above :

 

dialog switchbar {
  title "switchbar"
  size -1 -1 160 2000
  list 1, 1 -1 163 400, size
}

on *:dialog:switchbar:init:0:{
  mdx.load
  dll $udll SetDialog $dname style
  dll $udll SetControlMDX $dname 1 treeview haslines hasbuttons showsel rowselect insertdroptarget > $vdll
  ;Here we set the treeview function

<call DLL  to Dock Treeview in switchbar- This is a step depends on what your  Docking DLL is>
  load.switchbar
}

alias load.switchbar {
  ;clearing switchbar for refresh.
  did -r switchbar 1
  ;setting icons
  did -i switchbar 1 1 iconsize normal small
  did -i switchbar 1 1 seticon normal 72,system\dlls\shell.dll
  did -i switchbar 1 1 seticon normal 68,system\dlls\shell.dll
  did -i switchbar 1 1 seticon normal 71,system\dlls\shell.dll
  did -i switchbar 1 1 seticon normal 66,system\dlls\shell.dll
  did -i switchbar 1 1 seticon normal 76,system\dlls\shell.dll
  did -i switchbar 1 1 seticon normal 76,system\dlls\shell.dll
  did -i switchbar 1 1 seticon normal 76,system\dlls\shell.dll
  var %a = 1
  while (%a <= $scid(0)) {
  ;loading the connected servers!
    scon %a
    did -i switchbar 1 1 cb root
    did -a switchbar 1 +eb 1 1 $iif($scid(%a).network == $null,$scid(%a).server,$scid(%a).network)
    did -i switchbar 1 1 cb last
    did -a switchbar 1 +e 2 2 Channels $tab Channels
    did -i switchbar 1 1 cb last

  var %x = 1
  ;listing channels!
  while (%x <= $chan(0)) {
    did -a switchbar 1 + 2 2 $chan(%x) $tab $chan(%x)
    inc %x
  }

 

;Now Tree is :

;-Network

;--Channels

;----Sub channels


  did -i switchbar 1 1 cb up
  did -a switchbar 1 +e 3 3 Queries $tab Queries
  did -i switchbar 1 1 cb last

  var %x = 1
  ;listing queries!
  while (%x <= $query(0)) {
    did -a switchbar 1 + 3 3 $query(%x) $tab $query(%x)
    inc %x
  }
  inc %a
  }

 

;Now Tree is :

;-Network

;--Channels

;----Sub channels

;--Queries

;---Sub queries.....


  ;Making branch for dcc.
  did -i switchbar 1 1 cb root
  did -a switchbar 1 +eb 7 7 DCC $tab DCC
  did -i switchbar 1 1 cb last
  did -a switchbar 1 + 7 7 Get $tab Get
  did -i switchbar 1 1 cb last
  var %x = 1
  ;listing get files
  while (%x <= $get(0)) {
    did -a switchbar 1 + 7 7 $get(%x) $tab $get(%x)
    inc %x
  }

 

;Now Tree is :

;-Network

;--Channels

;----Sub channels

;--Queries

;---Sub queries.....

;--DCC

;---Gets

;----window gets

 

  did -i switchbar 1 1 cb up
  did -a switchbar 1 + 7 7 Send $tab Send
  did -i switchbar 1 1 cb last
  var %x = 1
  ;listing send files
  while (%x <= $send(0)) {
    did -a switchbar 1 + 7 7 $send(%x) $tab $send(%x)
    inc %x
  }

 

;Now Tree is :

;-Network

;--Channels

;----Sub channels

;--Queries

;---Sub queries.....

;--DCC

;---Get

;----window gets

;---Send

;----window send

  did -i switchbar 1 1 cb up
  did -a switchbar 1 + 7 7 Chat $tab Chat
  did -i switchbar 1 1 cb last
  var %x = 1
  ;Listing chat windows
  while (%x <= $chat(0)) {
    did -a switchbar 1 + 7 7 $chat(%x) $tab $chat(%x)
    inc %x
  }
  did -i switchbar 1 1 cb up
}

Events :
You are still here? heh. Congrats you made it this far. Here is  where it starts getting easy until the sclick events! Right here i will just show you the events, you need to copy them into your script and they should work fine.

alias query { query $1- | .timer -m 1 1 load.switchbar }
alias server { server $1- | .timer -m 1 1 load.switchbar }

on *:join:#:{ if ($nick == $me) { .timer -m 1 1 load.switchbar } }
on *:connect:{ .timer -m 1 1 load.switchbar }
on *:part:#:{ if ($nick == $me) { .timer -m 1 1 load.switchbar } }
on *:open:@:{ .timer -m 1 1 load.switchbar }
on *:close:@:{ .timer -m 1 1 load.switchbar }
on *:open:?:{ .timer -m 1 1 load.switchbar }
on *:close:?:{ .timer -m 1 1 load.switchbar }
on *:close:*:{ if ($target == "status window") { .timer -m 1 1 load.switchbar } }

They are pretty much self explanatory.

 

; I think these code  waste a lot of times because It's update  all switchbar  but not individual  branches , It can be easily change with a bit knowledge about Cb commands and /did -a  , However  I don't intend to rewrite It , may be It's your exercise  to familiar  with Cb and  /did -a commands ( Niceboy_DvD)

 

SCLICK Events! (Chapter 5):
Now comes the hardest part, this might be a little bit complex but i will try to explain it to the best of my ability.
Like before i'll paste the code and explain it, before reading this you should have a basic understanding of Multi Serv aliases.
Type /help multi serv for more information on the subject.

on *:dialog:switchbar:sclick:*:{
  if ($did == 1) {
  tokenize 32 $did(1,1,1)
  if ($4) && (!$5) {
     scon $calc($4 - 1)
     ;right here it is changing the scon so you can show the status window on the selected server
     window -a "status window"
     ;activating status window the the scon server.
   }
  elseif ($5 = 2) && ($6) {
    scon $calc($4 - 1)
    ;right here it is changing the scon so you can show the channel window on the selected server
    window -a $chan($calc($6 - 1))
    ;activating channel window the the scon server.
   }
  elseif ($5 = 3) && ($6) {
     scon $calc($4 - 1)
     ;right here it is changing the scon so you can show the query window on the selected server
     window -a $query($calc($6 - 1))
     ;activating query window the the scon server.
   }
   ;that is basically all you need for the channel/query/server windows
   if ($calc($4 - 1) > $scid(0)) {
   ;Checking to see if it is the DCC branch
    if ($6) {
      if ($5 == 2) {
       ;Checking if the active branch is gets.
        window -a "Get $get($calc($6 - 1)) $get($calc($6 - 1)).file $+ "
       ;Activating, or showing the selected get window
      }
      elseif ($5 == 3) {
         ;Checking if the active branch is sends.
         window -a "Send $send($calc($6 - 1)) $send($calc($6 - 1)).file $+ "
         ;Activating, or showing the selected send window
      }
      elseif ($5 == 4) {
        ;Checking if the active branch is Chats.
        window -a = $+ $chat($calc($6 - 1))
         ;Activating, or showing the selected chat window
      }
    }
  }
}

This section  is very basic  just  use tokenize  to get data from line 1 = $did(1,1,1) (when user click a 'Data line' in treeview),  , similar  our pages  , but  he use  directly  and It should be avoid because It's quite hard to handle  what pages return. we can rewrite  here a little like

on *:dialog:switchbar:sclick:*:{
  if ($did == 1) {
  tokenize 32 $mdx-info($dname,$did).select

}

.........................

}

and then the paramters  in $1-  degree some points, you could see it clearly  when you try :

 

on *:dialog:switchbar:sclick:*:{
  if ($did == 1) {
  tokenize 32 $mdx-info($dname,$did).select

  echo -s $1-

 }

}

 

The Last is some tips , may be It's useful :

- Try to make your code  clearly   and  Add some  comments  for them

- you  should know  where  you  place  a command  and  It's useful or  just a redundancy

- $ifmatch  and  tokenize  , didtok , $result ,$iif   is very useful  ,if you use it  right the way  (try to use it in your script)

- Avoid  repeatly  code  by using alias

- worse code  is reduced  if you have a plan for  them , you should  know  your direction, before you  code  a script (or everything)

- avoid bugs  by  checking  script carefully  with the "seldom case"  and  "common case" , and try to use it  like  a person who never use it before , It's good  to check some silly bugs

 

Our Jouney  with MDX should be finished here, I will add some more information  If  I could remember or  I think It's useful for you . if you have  any questions or want to ask sth  feel free to mail or pmsg  me .But I don't know If I have time or not

..................

 

Credits

.....................